package com.company.class7;

/**
 * @Classname RegexMeta
 * @Description 类型说明
 * @Date 2022/5/2 15:13
 * @Created by zbw
 */

public class RegexMeta {
    public static void main(String[] args) {
        String roy = "roy老师";
        String will = "will老师";

        //matches用来验证一个字符串是否符合正则表达式定义的规则
        //是整个字符串，和正则定义的规则是完全相等的，不是包含，可以省略^和$
        System.out.println(roy.matches("^.....$"));
        //相等
        System.out.println(roy.matches("...老师"));
        //不相等
        System.out.println(roy.matches("...老"));
        //\\W是包含其它特殊字符的
        System.out.println(roy.matches("...老\\W"));

        System.out.println("--------------------------量词--------------------");
        //量词：{数量}
        System.out.println(roy.matches(".{3}老师"));
        System.out.println(will.matches(".{4}老师"));

        System.out.println("----------------量词范围-------------");
        //让will和roy都能满足的表达式：任意字符出现3到4次
        System.out.println(roy.matches(".{3,4}老师"));
        System.out.println(will.matches(".{3,4}老师"));

        System.out.println("-----------------------");
        String regex = "[wioryl]{3,4}老师";
        System.out.println(roy.matches(regex));
        System.out.println(will.matches(regex));
        System.out.println("woy老师".matches(regex));
        //包含了元字符组以外的字符
        System.out.println("wora老师".matches(regex));
        //必须带老师
        System.out.println("wor".matches(regex));
        //长度不是3，4
        System.out.println("wiory老师".matches(regex));


        //词组，表示一串完整的字符串。顺序和个数必须一致
        //可以代表：r老师  o老师  y老师
        System.out.println("--------------------元字符对比----------------------");
        String metaCon = "[roy]老师";
        System.out.println("r老师".matches(metaCon));
        System.out.println("y老师".matches(metaCon));
        System.out.println("o老师".matches(metaCon));
        //false，只代表一个字母
        System.out.println("roy老师".matches(metaCon));


        //只能是roy老师
        System.out.println("----------------------------词组量词的对比---------------");
        String word = "(roy)老师";
        System.out.println("r老师".matches(word));
        System.out.println("roy老师".matches(word));

    }
}
